﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MathLib;
using System.Data.OleDb;
using System.IO;


namespace Demog {
    public partial class PopulationForm : Form {
        public PopulationForm() {
            InitializeComponent();
        }



        private void PrintMatrix(DataGridView dgv, Matrix m) {
            DataTable table = CreateTable(m.NoRows, m.NoCols);
            for (int i = 0; i < m.NoRows; i++) {
                DataRow dr = table.Rows[i];
                for (int j = 0; j < m.NoCols; j++)
                    dr[j] = m[i, j];
            }

            dgv.DataSource = table;
        }

        private DataTable CreateTable(int rows, int columns) {
            DataTable t = new DataTable();
            for (int j = 0; j < columns; j++)
                t.Columns.Add();
            for (int i = 0; i < rows; i++)
                t.Rows.Add();

            return t;
        }

        private void bModeling_Click(object sender, EventArgs e) {
            try {
                int groupCount = int.Parse(cbGroupCount.SelectedItem.ToString());
                int liveLength = int.Parse(tbLiveLength.Text);
                int populationsCount = int.Parse(tbPopulationsCount.Text);
                PopulationModeling test = new PopulationModeling(liveLength, groupCount, populationsCount);
                Matrix[] P = test.GeneratePopulation();
                SimulatedPopulation popForm = new SimulatedPopulation(P, test.PopulationMatrixes,test.Period, groupCount);
                popForm.Show();

            } catch (Exception exe) {
                MessageBox.Show("Заполните все поля", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
               
            }

         
        }

        private void bClose_Click(object sender, EventArgs e) {
            Close();
        }
    }
}
